package com.qdlc.p2p.biz.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.qdlc.p2p.biz.service.UserBaseInfoService;
import com.qdlc.p2p.dal.common.model.jpa.QueryParam;
import com.qdlc.p2p.dal.dao.UserBaseInfoDao;
import com.qdlc.p2p.dal.dto.UserBaseInfo;

/**
 * 用户基本信息
 * 
 * @author wzh
 * @version 2.0
 * @since 2014年11月4日
 */
@Service("userBaseInfoService")
public class UserBaseInfoServiceImpl implements UserBaseInfoService {

	@Resource
	private UserBaseInfoDao userBaseInfoDao;
	
	@Override
	public UserBaseInfo findByUserId(long userId) {
		return userBaseInfoDao.findObjByProperty("user.userId", userId);
	}
	
	@Override
	public void save(UserBaseInfo userBaseInfo) {
		
        QueryParam param = QueryParam.getInstance();
        param.addParam("user.userId", userBaseInfo.getUser().getUserId());
        UserBaseInfo baseInfo = userBaseInfoDao.findByCriteriaForUnique(param);
        if(baseInfo == null){
        	userBaseInfoDao.save(userBaseInfo);
        }else{
        	userBaseInfo.setId(baseInfo.getId());
        	userBaseInfo.setUser(baseInfo.getUser());
        	userBaseInfoDao.update(userBaseInfo);
        }
	}

}
